import { UserProfilesAPI } from '@/requst/api'
export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: 'nicheng',
            coin: 0,
            headImg: require('../../assets/img/service.848ec511.png')
        },
        cartTotal: 0
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        // 初始化仓库属性的
        initUserInfo(state) {
            state.userInfo = {
                nickName: 'nicheng',
                coin: 0,
                headImg: require('../../assets/img/service.848ec511.png')
            }
            state.cartTotal = 0;
        }
    },
    actions: {
        async asyncchangeUserInfo({ commit }) {
            let user = await UserProfilesAPI();
            // console.log("用户信息：", user);
            // 2.更新vuex中用户
            commit("changeUserInfo", user.data.data)
        }
    }
}